// xc_lshop/distr/manage/myteam.js
var actbill = require('../model/distribution_team.js')
Page({
  mixins: [require('../../../xc/mixins/basicMixin')],
  /**
   * 页面的初始数据
   */
  data: {
    tabstatus: "0",
    loading: true,
    modellist: [],
    memberinfo: {},
    xtitle: "订单列表"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  setconfig(config) {
    var update = {};

    if (config.distribution && config.distribution.distext && config.distribution.distext.center) {
      update['xtitle'] = config.distribution.distext.center.disorder
    }

    this.setData(update)
  },
  afterlogin: function (options, config, userinfo) {
    this.setconfig(config)

    if (!config.distribution || config.distribution.status != 1) {
      wx.redirectTo({
        url: config.basic.homeurl,
      })
      // wx.navigateTo({
      //   url:  config.basic.homeurl,
      // })
      return
    } else {
      if (userinfo['memberinfo']) {
        if (userinfo['memberinfo']['is_distribution'] == -1) {
          var link = "/xc_lshop/distr/info/apply"
          this.pageback(link,true)
        } else {
          this.setData({
            memberinfo: userinfo.memberinfo
          })
          this.getpagelist(1)
        }
      } else {
        this.pageback()
      }


    }
  },
  onNavChange(e) {
    var that = this
    if (this.data.tabstatus != e.detail.name) {
      this.setData({
        tabstatus: e.detail.name
      })
      this.getpagelist(1);
    }

  },
  getpagelist(rest, strwhere) {
    var that = this
    if (rest == 1) {
      that.setData({
        modellist: []
      });
      if (!strwhere) {
        strwhere = {}
      }
      strwhere["status"] = this.data.tabstatus
    }
    this.setData({
      isload: true
    })
    actbill.distrorderoffset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};
      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      updatemdoel["isload"] = false
      that.setData(updatemdoel);
    })
    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

    this.getpagelist(1)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

    this.getpagelist(-1)
  },


})